export default {
    name: 'account',
    components: {
        check: () =>
            import('../../socical/socialCheck/check.vue')
    },
    data() {
        return {
            acountTitle: '对公账户充值（未匹配）',
            Item: '1', //充值
            cash: false, //充值提示
            success: false, //充值成功
            company: {
                oppaccountno: "", //转账方账号
                rechargdate: "", //充值时间
                oppaccountname: "", //转账方账户名称
                startdate: "", //开始
                enddate: "" //结束
            },
            onplaycash: {
                accessoryid: '',
                matchingid: '', //未匹配编码
                companyid: '',
                accountname: '',
                totalfee: null,
                oppaccountname: "",
                oppaccountno: ""
            },
            imageUrl: '',
            AccountPlayCash: [],
            allCompanyname: [], //对应所有公司
            accountName: [],
            pagination: {
                total: 0,
                pageNum: 1,
                pageSize: 10
            },
            isShow: true,
            loading: false,
            checkFlag: false,
            companyname: '',
            companyid: '',
            global: {},
            searchCity: {
                province: '',
                city: '',
                area: '',
                citys: []
            },
            level: '',
            optionCompany: [],
            optShowOne: false,
            optShowTwo: false,
            warnDialogVisible: false,
            reportContent: ""
        }
    },
    props: ['type'],
    mounted() {

    },
    created() {
        this.global = this.GLOBAL;
        let department = JSON.parse(localStorage.getItem('userinfo')).department;
        if (department == "充值一部") {
            this.optShowOne = true;
            this.optShowTwo = false
        } else if (department == "充值二部") {
            this.optShowOne = false;
            this.optShowTwo = true
        }
        this.getAuthority();
        this.getTableData();
    },
    methods: {
        getAuthority() {
            let userinfo = localStorage.getItem('userinfo');
            userinfo = JSON.parse(userinfo);
            this.level = userinfo.level;
            this.searchCity.province = +userinfo.province || '';
            this.searchCity.city = +userinfo.city || '';
            this.searchCity.area = +userinfo.area || '';
            this.searchCity.citys = [];
            this.searchCity.citys.push(+userinfo.province);
            this.searchCity.citys.push(+userinfo.city);
            this.searchCity.citys.push(+userinfo.area);
        },
        getTableData() {
            this.loading = true;
            var obj = {
                // companyname: this.company.name,
                // rechargname: this.company.rechargname,
                pagenum: this.pagination.pageNum,
                pagesize: this.pagination.pageSize,
                oppaccountno: this.company.oppaccountno,
                startdate: this.company.startdate,
                enddate: this.company.enddate,
                // rechargdate: this.company.rechargdate,
                oppaccountname: this.company.oppaccountname,
                // province: this.searchCity.province,
                // city: this.searchCity.city,
                // area: this.searchCity.area
            }
            this.$axios.post('/app/v1/platform/recharge/offlineNoMatchingList', obj).then(resp => {
                if (resp.data.code == '1') {
                    this.AccountPlayCash = resp.data.data.list;
                    this.pagination.total = parseInt(resp.data.data.totalnum);
                    this.loading = false;
                }
            })
        },
        //查询
        SearchBtn() {
            this.pagination.pageNum = 1;
            this.getTableData();
        },
        //分页查询
        AccountCurrentChange(val) {
            this.pagination.pageNum = val;
            this.getTableData();
        },
        /*充值*/
        OnlinePlay(row) {
            this.onplaycash.matchingid = row.matchingid;
            this.onplaycash.oppaccountname = row.oppaccountname;
            this.onplaycash.oppaccountno = row.oppaccountno;
            this.onplaycash.totalfee = row.totalfee;


            // if (row.paymentname) {
            // let ItemCash = {
            //     companyid: row.companyid,
            //     // companyname: row.companyname,
            //     // accountname: row.paymentname
            // }
            // this.onplaycash.companyid = ItemCash.companyid;
            this.getAccountNumber(row.oppaccountno, row.oppaccountname);
            this.Item = '2';
            this.acountTitle = '充值';
            // } else {
            //     this.$message({
            //         message: '该企业未在企业端填写付款户名，无法进行充值操作',
            //         type: 'warning'
            //     });
            // }
        },
        /*添加凭证图片*/
        AddImgInfo() {
            let file_ipt = this.$refs.file_ipt;
            let file = file_ipt.files[0];
            let filetype = file.name.split('.')[1];
            if (filetype === 'png' || filetype === 'jpeg' || filetype === 'jpg') {
                let reader = new FileReader();
                let imgObj = new Image();
                let imgUrlBase64;
                imgUrlBase64 = reader.readAsDataURL(file);
                reader.onloadend = () => {
                    imgUrlBase64 = reader.result; // base64就是图片的转换的结果
                    imgObj.src = imgUrlBase64;
                    imgObj.onload = () => {
                        this.imageUrl = imgUrlBase64;
                        this.updateimg(filetype);
                    }
                };
            } else {
                this.$message({
                    message: '上传文件格式不正确，请重新上传',
                    type: 'warning'
                });
            }
        },
        updateimg(filetype) {
            let imgBase64 = this.imageUrl.split(',')[1];
            let obj = {
                accname: filetype, //文件格式
                accessoryid: '',
                filecontent: imgBase64,
                updownmark: '0'
            }
            this.$axios.post("/system/v1/common/upAndDown", obj).then(resp => {
                this.isShow = false;
                if (resp.data.code === 1) {
                    this.onplaycash.accessoryid = resp.data.data.accessoryid;
                }
            })
        },
        //公司详情
        OnlineCompay(row) {
            this.companyid = row.companyid;
            this.companyname = row.companyname;
            this.checkFlag = true;
        },

        trueMoney(v) {
            // var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
            var exp = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
            // var exp = /^([1-9][\d]{0,7}|0)?$/;
            if (exp.test(v)) {
                return true;
            } else {
                // that.disabled = true;
                return false;
            }
        },
        //充值
        SubmitCash() {
            this.onplaycash.accountname = this.onplaycash.oppaccountname;
            if (this.onplaycash.totalfee) {
                let current = this.trueMoney(this.onplaycash.totalfee);
                if (current) {} else {
                    // this.$message('请填写正确的金额信息(0.00)！');
                    this.$message.warning('充值金额只能为正整数！');
                    return;
                }
            }
            if (this.onplaycash.accountname && this.onplaycash.companyid && this.onplaycash.totalfee && this.onplaycash.accessoryid) {
                // this.cash = true;
                this.warnDialogVisible = true;
                // this.submit();
            } else {
                this.$message('请填写完整充值信息！');
            }

        },

        goBack() {
            this.Item = '1';
            this.imageUrl = "";
            this.isShow = true;
            this.acountTitle = '对公账户充值';
            this.clearData();

        },
        //取消充值
        cancle() {
            this.cash = false;
        },
        //确定充值上报
        submit() {
            if (!this.reportContent) {
                this.$message({
                    type: "warning",
                    message: "上报内容不能为空!"
                });
                return;
            }
            var obj = {
                id: this.onplaycash.matchingid,
                reporttype: '13',
                content: this.reportContent,
                companyid: this.onplaycash.companyid,
                totalfee: this.onplaycash.totalfee,
                accessoryid: this.onplaycash.accessoryid,
                goodsname: this.onplaycash.oppaccountname,
                oppaccountno: this.onplaycash.oppaccountno,
                oppaccountname: this.onplaycash.oppaccountname,
            }
            this.reportAjax(obj);
        },
        //上报里确定
        confirmReport() {
            this.submit();
        },
        //上报请求
        reportAjax(obj) {
            this.$axios
                .post("/app/v1/platform/unusual/reportSubmit", obj)
                .then(res => {
                    if (res.data.code == "1") {
                        this.cash = false;
                        this.warnDialogVisible = false;
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                        this.goBack();
                    } else if (res.data.code == "365") {
                        this.cash = false;
                        this.warnDialogVisible = false;
                        this.$message({
                            message: "上报记录已存在,请等待充值二部处理",
                            type: "error"
                        });
                        this.goBack();

                    } else {
                        this.cash = false;
                        this.$message({
                            message: res.data.message,
                            type: "error"
                        });
                    }
                });
        },

        clearData() {

            this.onplaycash.accessoryid = '';
            this.onplaycash.matchingid = '';
            this.onplaycash.companyid = '';
            this.onplaycash.accountname = '';
            this.onplaycash.totalfee = null;
            this.onplaycash.oppaccountname = "";
            this.onplaycash.oppaccountno = "";
            this.imageUrl = "";
        },
        handleSizeChange(val) {
            this.pagination.pageNum = 1;
            this.pagination.pageSize = val;
            this.getTableData();
        },

        //根据转账账户或者账号匹配公司
        getAccountNumber(oppaccountno, oppaccountname) {
            this.loading = true;
            var obj = {
                oppaccountno: oppaccountno,
                oppaccountname: oppaccountname
            }
            this.getCompany(obj);

        },
        getCompany(obj) {
            this.$axios.post('/app/v1/platform/recharge/matchingCompanyList', obj).then(resp => {
                if (resp.data.code == '1') {
                    this.allCompanyname = resp.data.data;
                    this.loading = false;
                }
            })
        },
        changeCompanyname(val) {
            let obj = this.allCompanyname.find((item) => {
                return item.companyid === val;
            });
            this.onplaycash.companyname = obj.companyname;

        },
        handleCompanynameFilter(val) {
            if (val.trim() != '') {
                var obj = {
                    oppaccountname: val
                }
                this.getCompany(obj);

            }


        },
        closeWarnDialog() {
            this.reportContent = "";
        },

    },

}